var toolUtil = require('../common/utils/toolUtil');


exports.preprocess = function (req, res, next) {

    var tempArray = req.url.split('/');
    var token = req.query.token ? req.query.token : tempArray[tempArray.length - 2];

    if (token.length > 24 && req.url.indexOf('checkToken') == -1) {
        req.url = req.url.replace(token, toolUtil.getUserIdByToken(token))
    }

    req.body = JSON.parse(JSON.stringify(req.body).replace(/objId/g, '_id'));

    if (req.body.images != null && req.body.images.length > 0) {
        req.body.images.forEach(function (image) {
            if (image.imageURL.indexOf('/') != 0) {
                image.imageURL = '/' + image.imageURL;
            }
        })
    }
    next();

};
